package com.chen.tliaswebtest.service.impl;

import com.chen.tliaswebtest.mapper.OperateLogMapper;
import com.chen.tliaswebtest.pojo.OperateLog;
import com.chen.tliaswebtest.pojo.PageResult;
import com.chen.tliaswebtest.service.OperationService;
import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageMethod;
import org.springframework.stereotype.Service;

/**
 * @author chen
 * @version 1.0
 * @create_date 2025/7/27
 * 操作日志服务实现类
 */
@Service
public class OperationServiceImpl implements OperationService {
    private final OperateLogMapper operateLogMapper;

    public OperationServiceImpl(OperateLogMapper operateLogMapper) {
        this.operateLogMapper = operateLogMapper;
    }

    @Override
    public void addLog(OperateLog operateLog) {
        // 添加日志
        operateLogMapper.add(operateLog);
    }

    @Override
    public PageResult pageLog(Integer page, Integer pageSize) {
        // 分页设置
        PageMethod.startPage(page, pageSize);
        Page<OperateLog> p = (Page<OperateLog>) operateLogMapper.selectAll();
        return PageResult.builder().total(p.getTotal()).rows(p.getResult()).build();
    }
}
